package com.wf.pattern.observer.demo;

import lombok.Setter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 功能描述
 *
 * @since 2021/10/30
 */
public class BellEventSource {
   private List<Listener> listeners = new ArrayList<>();

   public BellEventSource() {
   }

   public void addListener(Listener listener) {
       listeners.add(listener);
   }

   public void removeListener(Listener listener) {
       listeners.remove(listener);
   }

   public void ring(boolean sound) {
       String type = sound ? "begin" : "end";
       System.out.println(type + " class");

   }

   public void notify(RingEvent event) {
       for (Listener next : listeners) {
           next.handleRing(event);
       }
   }

}
